<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%
	String path = request.getContextPath();
	String width = "220";
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />

<style type="text/css">
</style>

</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm">
				<div class="fieldset1 tabel_col clearFix">
					
					<div class="caption">
						<span class="title">付款单</span>
					</div>

					<div class="fieldBox col_50">
						<div class="label">收款账户名称</div>
						<div class="field">
							<input id="rcptUnt" name="rcptUnt" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true,maxlength:30}"
								value="${fncCapPayeeInfoBigVO.rcptUnt}" /> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款账户名称</div>
						<div class="field">
							<input id="payer" name="payer" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.payer}" /> 
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收款账号</div>
						<div class="field">
							<input id="accNo" name="accNo" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true,maxlength:30}"
								value="${fncCapPayeeInfoBigVO.accNo}" /> *
						</div>
					</div>
					
					<div class="fieldBox col_50">
						<div class="label">付款账号</div>
						<div class="field">
							<input id="payerAccNo" name="payerAccNo" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.payerAccNo}" />
								
								<%-- <c:if test="${operate == 'add' || operate == 'update'}">
										<span class="sq-button sq-button-round" 
											onclick="sysBkAccInfoChoose();">选择付款账号</span>
								</c:if> --%>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收款银行</div>
						<div class="field">
							<input id="payeeBkNm" name="payeeBkNm" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true}"
								value="${fncCapPayeeInfoBigVO.payeeBkNm}" /> *
						</div>
					</div>
					
					<div class="fieldBox col_50">
						<div class="label">类型</div>
						<div class="field">
							<input id="type" name="type" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.type}" /> 
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">收款银行行号</div>
						<div class="field">
							<input id="payeeBkNo" name="payeeBkNo" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true,maxlength:20}"
								value="${fncCapPayeeInfoBigVO.payeeBkNo}" /> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款银行</div>
						<div class="field">
							<input id="payerBkNm" name="payerBkNm" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.payerBkNm}" /> 
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">对公对私</div>
						<div class="field">
							<select id="pubPri" name="pubPri" ligerui="width: <%=width%>" validate="{required:true}">
								<option value="">请选择</option>
								<option value="1"
									<c:if test="${1==fncCapPayeeInfoBigVO.pubPri}">selected="selected"</c:if>>对私</option>
								<option value="0"
									<c:if test="${0==fncCapPayeeInfoBigVO.pubPri}">selected="selected"</c:if>>对公</option>
							</select> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款银行行号</div>
						<div class="field">
							<input id="payerBkNo" name="payerBkNo" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.payerBkNo}" /> 
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">费用种类</div>
						<div class="field">
							<input id="feeType" name="feeType" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{required:true,maxlength:20}"
								value="${fncCapPayeeInfoBigVO.feeType}" /> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款公司主体</div>
						<div class="field">
							<input id="payerMain" name="payerMain" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								value="${fncCapPayeeInfoBigVO.payerMain}" /> 
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">付款类型</div>
						<div class="field">
							<select id="payType" name="payType" ligerui="width: <%=width%>"
								validate="{required:true}" onchange="hiddenOrShowRelPrjDiv();">
								<option value="">请选择</option>
								<c:forEach items="${payTypeList}" var="item">
									<option value="${item.key}"
										<c:if test="${item.key ==fncCapPayeeInfoBigVO.payType}">selected="selected"</c:if>>${item.value}</option>
								</c:forEach>
							</select> *
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">转账金额</div>
						<div class="field">
							<input id="payAmt" name="payAmt" type="text"
								class="ui-textbox" ligerui="width: <%=width%>"
								validate="{number:true,min:0,required:true,decimallen:2}"
								value="${fncCapPayeeInfoBigVO.payAmt}" /> *
						</div>
					</div>
					
					
					
					<div class="fieldBox col_100">
						<div class="label">付款备注</div>
						<div class="field">
							<textarea id="remark" name="remark" style="width:90%" class="l-textarea" >${fncCapPayeeInfoBigVO.remark}</textarea>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际付款金额</div>
						<div class="field">
							${fncCapPayeeInfoBigVO.actPayAmt}
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">实际付款时间</div>
						<div class="field">
							<fmt:formatDate type="date" value="${fncCapPayeeInfoBigVO.actPayTm }"/>
						</div>
					</div>

<!-- 附件上传 -->
<c:if test="${operate == 'update'  || operate == 'add' }">
<div class="fieldBox col_100" >
<div class="label">附件上传</div>
<div class="field">
     <jsp:include page="../../rfbuss/frCommFilesUpload.jsp" flush="true" >
		<jsp:param name="filePath" value="ref"/>
	 </jsp:include>
	 
	<div id="fileUpload" class="upfileBoxs"></div>
	<span class="sq-button sq-button-hasicon" id="btnUpload" onclick="ajaxFileUploadImg('uploads1',2)">
		<i class="sqBtnIco_9"></i>上传
	</span>
</div>
</div>
</c:if>

<!-- 附近列表 -->
<div class="fieldBox col_100">
	<div style="width: 98%; margin-left: 1%;">
	<jsp:include page="../../rfbuss/frCommFilesList.jsp" flush="true" ></jsp:include>
		<div id="ligergrid_file2" class="sq-grid"></div>
	</div>
</div>
<div class="fieldBox col_100">
	<div class="label"></div>
	<div class="field"></div>
</div>


			<!-- 关联项目信息 -->
			<%@ include file="fncCapPayeeInfoBigPrj.jsp"%>

				<div class="btnsBox">
					<c:if test="${operate == 'add' ||operate == 'update'}">
						<span id="saveBtn" class="sq-button sq-button-round"
							onclick="save();">保存</span>
					</c:if>
					<!-- 出纳付款节点 -->
				<c:if test="${tabFlag=='101'}">   
						<div class="fieldBox col_33">
							<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendWait'}">
								<span id="sendBtn" class="sq-button sq-button-round" onclick="sendPay()" >发送付款</span>
							</c:if>
							<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendFailure'|| fncCapPayeeInfoBigVO.sendSt=='payFailure' || fncCapPayeeInfoBigVO.sendSt=='cancelled'}">
								<span id="sendBtn" class="sq-button sq-button-round" onclick="sendPay()" >重新发送付款</span>
							</c:if>
							<c:if test="${fncCapPayeeInfoBigVO.sendSt=='paySuccess' || fncCapPayeeInfoBigVO.sendSt=='sending' || fncCapPayeeInfoBigVO.sendSt=='sendSuccess' }"> 
								<span  class="sq-button sq-button-round disabled"  disabled>发送付款</span>
							</c:if> 
						</div>
						<div class="fieldBox col_33">
							<div class="label">付款状态</div>
							<div class="field">
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendWait'}">待发送</c:if>
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sending'}">发送中</c:if>
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendSuccess'}">发送成功</c:if>
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendFailure'}">发送失败</c:if>
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='paySuccess'}">付款成功</c:if>
								<c:if test="${fncCapPayeeInfoBigVO.sendSt=='cancelled'}">已作废</c:if>
							</div>
						</div>
						<div class="fieldBox col_33">
							<div class="label">付款响应信息</div>
							<div class="field">
								${fncCapPayeeInfoBigVO.msg }
							</div>
						</div>
						<div class="fieldBox col_33">
						   <c:if test="${fncCapPayeeInfoBigVO.sendSt=='sendWait' || fncCapPayeeInfoBigVO.sendSt=='sending' }">
								<span id="successBtn" class="sq-button sq-button-round disabled " >网银付款记录查询</span>
							</c:if>
							 <c:if test="${fncCapPayeeInfoBigVO.sendSt!='sendWait'&& fncCapPayeeInfoBigVO.sendSt!='sending' }">
								<span id="successBtn" class="sq-button sq-button-round" onclick="paySuccess()">网银付款记录查询</span>
							</c:if>
						</div>
						<div class="fieldBox col_33">
							<div class="label">查询响应信息</div>
							<div class="field">
								${fncCapPayeeInfoBigVO.respMsg }
							</div>
						</div>
						<c:if test="${fncCapPayeeInfoBigVO.sign=='2' || fncCapPayeeInfoBigVO.respSign=='2'  }">
							<div class="fieldBox col_33">
								<font color="red">签名校验失败,请联系管理员核查!</font>
							</div>
						</c:if>
				</c:if>   
				</div>
				</div>
			</form>
			
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					 <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
                      <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
				</div>
			</div>
			
		</div>
	</div>
	<script type="text/javascript">
	 	var operate='${operate}'; 
		$(function() {
			$("#ligerForm").ligerForm({
		        validate : true
		    });
			
			//字段不可用
			liger.get("payer").setDisabled(true);
			liger.get("payerAccNo").setDisabled(true);
			liger.get("payerBkNm").setDisabled(true);
			liger.get("payerBkNo").setDisabled(true);
			liger.get("payerMain").setDisabled(true);
			liger.get("type").setDisabled(true);
			
			
			 // 验证值小数位数不能超过指定位数param  郭志强20170810
		    $.validator.addMethod("decimallen", function(value, element, param) {
		        var decimallen =eval("/^-?\\d+(\\.\\d{0," + param + "})?$/"); 
		        return this.optional(element) || (decimallen.test(value));
			}, "小数位数不能超过{0}位");
            
            <c:if test="${empty operate || operate == 'view'}">
          		//设置所有不可用
	        	setAllDisabled();
	        	loadFilesLiger("fncCapPayeeInfoBig", 2, "${fncCapPayeeInfoBigVO.id}", "no");
	        </c:if>
	        
	        <c:if test="${operate == 'update' }">
	        liger.get("payType").setDisabled(true);
		        loadFilesLiger("fncCapPayeeInfoBig", 2, "${fncCapPayeeInfoBigVO.id}", "yes");
	        </c:if>
	        <c:if test="${operate == 'add' }">
	        loadFilesLiger("fncCapPayeeInfoBig", 2, "${fncCapPayeeInfoBigVO.id}", "yes");
        	</c:if>
	    });
		
		//选择付款账号
	 	function sysBkAccInfoChoose(){
	 		<c:if test="${operate == 'add' || operate == 'update'}">
		         $.ligerDialog.open({title: '付款账号',height: 500,width: 850, url: '<%=path%>/system/sysBkAccInfo/toChooseListPage2.do?flag=dk'});
	 		</c:if>
	 	}
	 	//选择付款账号后，设置数据
	 	function setAccInfo(accNo,accNm,bkNm,bkNo,id,accTypNm){
	 		//console.log(bkNo);
	 		//$("#payAcc").val(id);//付款账号id
	 		$("#payerAccNo").val(accNo);//付款账号
	 		$("#payer").val(accNm=='null'?"":accNm);//付款账户名称
	 		$("#payerBkNm").val(bkNm=='null'?"":bkNm);//付款银行
	 		$("#payerBkNo").val(bkNo=='null'?"":bkNo);//付款银行行号
	 		$("#type").val(accTypNm=='null'?"":accTypNm);//类型
	 	}
	 	
		//不可用
		function setAllDisabled(){
			liger.get("rcptUnt").setDisabled(true);
			liger.get("payType").setDisabled(true);
			liger.get("accNo").setDisabled(true);
			liger.get("feeType").setDisabled(true);
			liger.get("payeeBkNm").setDisabled(true);
			liger.get("payerAccNo").setDisabled(true);
			liger.get("payeeBkNo").setDisabled(true);
			liger.get("payAmt").setDisabled(true);
			liger.get("pubPri").setDisabled(true);
			$('#remark').attr("disabled",true);
		}
		
		
		
		function save(){
			
			//验证
			var ligerForm = liger.get("ligerForm");
			if (!ligerForm.valid()) {
			    	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning",SQ_showButtons: true});
		            return ; 
		    }
		   
				
			//组织数据，提交后台
			var data = ligerForm.getData();
			
			data["id"] = "${fncCapPayeeInfoBigVO.id}";
			
			//付款类型:再融资首付款费用付款,验证关联项目信息/计费信息
			if($("#payType").val() == "3"){
				//alert($("#fundId").val()); 获取文本内容
				if(liger.get("fundId").getValue() == '') {//获取key
					$.ligerDialog.SQalert({content: "请选择关联金融机构",SQ_type: "warning"});
					return ;
				}
				if(liger.get("fncPrjId").getValue() == '') {
					$.ligerDialog.SQalert({content: "请选择关联项目",SQ_type: "warning"});
					return ;
				}
				/* if(liger.get("fncScmNm").getValue() == '') {
					$.ligerDialog.SQalert({content: "报价名称不能为空",SQ_type: "warning"});
					return ;
				} */
				if(liger.get("isXirr").getValue() == '') {
					$.ligerDialog.SQalert({content: "请选择是否更新实际XIRR(%)",SQ_type: "warning"});
					return ;
				}
				/* if(liger.get("xirrOld").getValue() == '') {
					$.ligerDialog.SQalert({content: "原实际XIRR(%)不能为空",SQ_type: "warning"});
					return ;
				} */
				if(liger.get("xirrNew").getValue() == '') {
					$.ligerDialog.SQalert({content: "请输入新实际XIRR(%)",SQ_type: "warning"});
					return ;
				}
				
				var _fncScmChrgParmBigList =  liger.get("scmChrg").getData(); 
				if(_fncScmChrgParmBigList.length == 0) {
					$.ligerDialog.SQalert({content: "请新增一条计费信息",SQ_type: "warning"});
					addNewScmChrg();//新增一条计费信息
					return ;
				}
				
				for (var i=0; i< _fncScmChrgParmBigList.length; i++){ 
					console.log(_fncScmChrgParmBigList[i]);
					//alert(_fncScmChrgParmBigList[i]['costNm']);
					if(!_fncScmChrgParmBigList[i]['costNm']) {
						$.ligerDialog.SQalert({content: "请选择费用名称",SQ_type: "warning"});
						return;
					}
					if(!_fncScmChrgParmBigList[i]['mrgnUseMtd']) {
						$.ligerDialog.SQalert({content: "请选择保证金到期处理方式",SQ_type: "warning"});
						return;
					}
					
					var costAmt = _fncScmChrgParmBigList[i]['costAmt'];
					if(!costAmt) {
						$.ligerDialog.SQalert({content: "请输入费用金额",SQ_type: "warning"});
						return;
					}
					//费用金额必须大于0;必须跟转账金额相等
					var costAmtNumber = Number(costAmt);
					if(costAmtNumber <=0) {
						$.ligerDialog.SQalert({content: "计费信息:费用金额必须大于0",SQ_type: "warning"});
						return;
					}
					
					
					var payAmt = Number(liger.get("payAmt").getValue());
					if(costAmtNumber != payAmt) {
						$.ligerDialog.SQalert({content: "计费信息:费用金额"+costAmtNumber+"必须等于转账金额"+payAmt,SQ_type: "warning"});
						return;
					}
					
					//设置"是否保证金"默认值否
					if(!_fncScmChrgParmBigList[i]['mrgnIs']) {
						_fncScmChrgParmBigList[i]['mrgnIs'] = 0; 
					}
					
					//设置"是否计入首付款"默认值 计入首付款
					if(!_fncScmChrgParmBigList[i]['costInTpCd']) {
						_fncScmChrgParmBigList[i]['costInTpCd'] = 1; 
					}
					//设置"首付款是否坐扣"默认值否
					_fncScmChrgParmBigList[i]['wthrDdct'] = 0; 
	    		}
				
				
				data["_fncScmChrgParmBigList"] = JSON.stringify(_fncScmChrgParmBigList);
			} 
			
			/* var manager = $("#scmChrg").ligerGetGridManager();
            var rows = manager.rows; 
            console.log(rows); */
			console.log(data);
			//return;
			
			var wait_dialog = null;
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/rfbase/fncCapPayeeInfoBig/save.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : LogUtils.LOG_CMM_DATA_LOADING,
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						saveFile2(msg.data);
						//$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
						alert(msg.info);
						Remove_navTab();//关闭当前页面
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					wait_dialog.close();
					$.ligerDialog.SQalert({
						content : "网络错误，请稍后重试",
						SQ_type : "error"
					});
				}
			});
		}
		//保存文件
		function saveFile2(pkId){
			var docArray = JSON.stringify(getUploadResultParams(2));
	        var url = "<%=path%>/rfcont/fncPrjContAudit/uploadAttchment.do";
        	if(null == docArray){
        		//无要上传的文件-直接结束
        		//top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        	}else{
		        if(pkId){//ID不为空执行
			        //赋值附件
			        var data = {
						"docArray":docArray,
						"pkId": pkId,
						"flag": "fncCapPayeeInfoBig"
					};
					//请求
			        AjaxUtils.ajaxPost(url, data, function(msg){
			        	if(msg.success == 1){
							 //top.$.ligerDialog.SQalert({content: info,SQ_type: "success"});
							 if(msg.data){
								 clearUploadResultParams(2);
							 }
						 }else{
							 UIUtils.alertError(msg.info);
						 }
			        }, true);
		        }else{
		        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
		        }
        	}
		}
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: i});
    		}
		}
		//点击“付款”时，调用拜特系统付款接口，进行付款
		function sendPay(){
			$.ligerDialog.confirm('确定发送拜特付款吗?', function (flag) {
				if(flag == false) return;
					var id="${fncCapPayeeInfoBigVO.id}";//付款单id
					var wait_dialog = null;
					$('#sendBtn').attr("disabled",true);
					$.ajax({
						type: 'post',
						dataType: 'json',
						data: {"id":id},
						url: '<%=path%>/rfbase/fncCapPayeeInfoBig/sendPay.do',
						beforeSend : function() {
							wait_dialog = $.ligerDialog.SQalert({content : LogUtils.LOG_CMM_DATA_LOADING,SQ_type : "waitting"});
						},
						success : function(msg) {
							wait_dialog.close();
							window.location.reload();
							if (msg.success == 1) {
								$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
								
							} else {
								$.ligerDialog.SQalert({content : msg.info,SQ_type : "error"});
							}
						},
						error : function(XMLHttpRequest, textStatus, errorThrown) {
							wait_dialog.close();
							window.location.reload();
							$.ligerDialog.SQalert({
								content : "网络错误，请稍后重试",
								SQ_type : "error"
							});
						}
					});
			});
		}
		//点击“付款完成”时，调用网银付款记录查询接口
		function paySuccess(){
			$.ligerDialog.confirm('确定查询网银付款吗?', function (flag) {
				if(flag == false) return;
			       var id="${fncCapPayeeInfoBigVO.id}";//付款单id
					var wait_dialog = null;
					$('#successBtn').attr("disabled",true);
					$.ajax({
						type: 'post',
						dataType: 'json',
						data: {"id":id},
						url: '<%=path%>/rfbase/fncCapPayeeInfoBig/getPaymentById.do',
						beforeSend : function() {
							wait_dialog = $.ligerDialog.SQalert({content : LogUtils.LOG_CMM_DATA_LOADING,SQ_type : "waitting"});
						},
						success : function(msg) {
							wait_dialog.close();
							window.location.reload();
							if (msg.success == 1) {
								$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
								
							} else {
								$.ligerDialog.SQalert({content : msg.info,SQ_type : "error"});
							}
						},
						error : function(XMLHttpRequest, textStatus, errorThrown) {
							wait_dialog.close();
							window.location.reload();
							$.ligerDialog.SQalert({
								content : "网络错误，请稍后重试",
								SQ_type : "error"
							});
						}
					});
			});
		}
	</script>
</body>
</html>
